package com.popcorn.notice.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.popcorn.action.Action;
import com.popcorn.action.ActionForward;
import com.popcorn.notice.dao.NoticeDAO;
import com.popcorn.notice.model.NoticeModel;

public class NoticeUpdateAction implements Action {

	@Override
	public ActionForward execute(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		
		int idx = Integer.parseInt(request.getParameter("idx"));
		
		NoticeDAO noticeDAO = new NoticeDAO();
		NoticeModel noticeModel = new NoticeModel();

   		boolean result=false;
   		
   		try{
   			noticeModel.setSEQ_BBS(idx);
   			noticeModel.setTITLE(request.getParameter("TITLE"));
   			noticeModel.setCONTENT(request.getParameter("CONTENT"));
   			noticeModel.setMOD_DTM(request.getParameter("MOD_DTM"));
   			noticeModel.setMOD_ID(request.getParameter("MOD_ID"));
	   		result=noticeDAO.modelUpdate(noticeModel);
	   		if(result==false){
	   			System.out.println("DB 수정 실패");
	   			return null;
	   		}
	   		System.out.println("DB 수정 성공");
		
		ActionForward forward= new ActionForward();
	   	forward.setRedirect(false);
   		forward.setPath("NoticeDetailDB.ao?idx="+idx);
   		return forward;
   		
   		}catch(Exception ex){
   			ex.printStackTrace();
   		}
		return null;
		
	}
}
